/*******************************************************************************
 * 版权：北京润尼尔网络科技有限公司，保留所有版权<br>
 * 版本：v1.0.0<br>
 * 文件：RectangleSelectionFeedbackPolicy.js<br>
 * 日期：2019年6月5日<br>
 * 作者: 李姣<br>
 * 功能：<br>
 * 
 * 修改记录：<br>
 * 日期 描述 更新功能<br>
 ******************************************************************************/

window.makeNamespace(window,"Rainier.UI.V2");

/**
 * 类型名称：Rainier.UI.V2.RectangleSelectionFeedbackPolicy<br>
 * 类型功能：直角选择策略<br>
 */
Rainier.UI.V2.RectangleSelectionFeedbackPolicy = draw2d.policy.figure.RectangleSelectionFeedbackPolicy.extend({

	NAME : "Rainier.UI.V2.RectangleSelectionFeedbackPolicy",

	/**
	 * 函数名称：Rainier.UI.V2.Draw2dGraphicalEditor.init<br>
	 * 函数功能：构造函数<br>
	 * 参数输入：objPro:ViewProperty
	 * 异常信息：无<br>
	 */
	init: function(attr, setter, getter){
		this._super(attr, setter, getter);
		this.recBgColor = attr.recBgColor;
		this.lineColor = attr.lineColor;
	},
	
	/**
	 * 函数名称：Rainier.UI.V2.Draw2dGraphicalEditor.storeExper<br>
	 * 函数功能：存储默认实验(主针对集成环境)<br>
	 * 参数输入：exper ： Object<br>
	 * 参数输出：无<br>
	 * 函数返回：无<br>
	 * 异常信息：无<br>
	 */
	onSelect: function(canvas, figure, isPrimarySelection){
		if(figure.selectionHandles.isEmpty()){
			// Add a dotted line rectangle to the figure. Override the show/hide method of the standard
			// figure to avoid adding these element to the hit test of the canvas. In this case the element
			// is just visible but not part of the model or responsible for any drag/drop operation
			// #2C70FF #2096fc
			var box = new draw2d.shape.basic.Rectangle({bgColor:null, dashArray:"- ", color:this.lineColor, stroke:0.5});
			box.hide= function(){
				// IMPORTANT
				// don't add/remove this rectangle to the canvas resizeHandles. This rect isn't responsible for any hitTest or
				// dragDrop operation
				//canvas.resizeHandles.remove(box);
				box.setCanvas(null);
			};
			box.show= function(canvas){
				box.setCanvas(canvas);
				// IMPORTANT
				// don't add/remove this rectangle to the canvas resizeHandles. This rect isn't responsible for any hitTest or
				// dragDrop operation
				//canvas.resizeHandles.remove(box);
				//canvas.resizeHandles.add(box);
				box.toFront(figure);
			};
			// create standard Resize handles for the figure
			//
			var r1= draw2d.Configuration.factory.createResizeHandle(figure,1); // 1 = LEFT TOP
			var r3= draw2d.Configuration.factory.createResizeHandle(figure,3); // 3 = RIGHT_TOP
			var r5= draw2d.Configuration.factory.createResizeHandle(figure,5); // 5 = RIGHT_BOTTOM
			var r7= draw2d.Configuration.factory.createResizeHandle(figure,7); // 7 = LEFT_BOTTOM
			figure.selectionHandles.add(r1);
			figure.selectionHandles.add(r3);
			figure.selectionHandles.add(r5);
			figure.selectionHandles.add(r7);
			r1.show(canvas);
			r3.show(canvas);
			r5.show(canvas);
			r7.show(canvas);

			r1.setBackgroundColor(this.recBgColor);
			r3.setBackgroundColor(this.recBgColor);
			r5.setBackgroundColor(this.recBgColor);
			r7.setBackgroundColor(this.recBgColor);

			// change the look&feel of the corner resizehandles if the
			// figure isn't resizeable
			//
			if(figure.isResizeable()===false) {
				r1.setBackgroundColor(null);
				r3.setBackgroundColor(null);
				r5.setBackgroundColor(null);
				r7.setBackgroundColor(null);
				r1.setDraggable(false);
				r3.setDraggable(false);
				r5.setDraggable(false);
				r7.setDraggable(false);
			}

			// show only the additional resizehandles if the figure is resizeable and didn't care about
			// the aspect ration
			//
			if((!figure.getKeepAspectRatio()) && figure.isResizeable())
			{
				var r2= draw2d.Configuration.factory.createResizeHandle(figure,2); // 2 = CENTER_TOP
				var r4= draw2d.Configuration.factory.createResizeHandle(figure,4); // 4 = RIGHT_MIDDLE
				var r6= draw2d.Configuration.factory.createResizeHandle(figure,6); // 6 = CENTER_BOTTOM
				var r8= draw2d.Configuration.factory.createResizeHandle(figure,8); // 8 = LEFT_MIDDLE
				figure.selectionHandles.add(r2);
				figure.selectionHandles.add(r4);
				figure.selectionHandles.add(r6);
				figure.selectionHandles.add(r8);
				r2.show(canvas);
				r4.show(canvas);
				r6.show(canvas);
				r8.show(canvas);
			}

			r2.setBackgroundColor(this.recBgColor);
			r4.setBackgroundColor(this.recBgColor);
			r6.setBackgroundColor(this.recBgColor);
			r8.setBackgroundColor(this.recBgColor);

			// add the reference of the "ant box" to the figure as well. But wee add them
			// to the end of the array because inherit classes expect the resizehandles
			// on index 0-7.
			//
			figure.selectionHandles.add(box);

			// call the box.show() at last to ensure that the resize handles are above the 
			// rectangle. The rectangle did a toFront(parentShape);
			box.show(canvas);


		}
		this.moved(canvas, figure);		
	},

});